﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace SmartMotion.Core
{
    public static class TablayOutEx
    {
        public static void ChildrenMoveToCenter(this TableLayoutPanel tab)
        {
            var cellWidth = tab.Width / tab.ColumnCount;
            var cellHeight = tab.Height / tab.RowCount;
            foreach (Control ctrl in tab.Controls)
            {
                if (ctrl.Dock != DockStyle.None) continue;  

                int marLeft = (cellWidth - ctrl.Width) / 2;
                int marTop = (cellHeight - ctrl.Height) / 2;
                ctrl.Margin = new Padding(marLeft, marTop, 3, 3);
            }
        }   

    }
}
    